(function () {
    'use strict';
    angular.module('module.business')
        .controller('MenuFunctionController', MenuFunctionController);
    MenuFunctionController.$inject = ['$rootScope', '$scope', '$filter', '$uibModal', '$http', '$state','$uibModalInstance', 'i18nService'];

    function MenuFunctionController($rootScope, $scope, $filter, $uibModal, $http, $state, $uibModalInstance, i18nService) {
        var vm = $scope;
        vm.activate = activate;     //初始化
        vm.cancel = cancel;//关闭弹窗
        vm.update = update;//保存
        vm.retrieveAllMenuFunctionm = retrieveAllMenuFunctionm;//功能列表

        vm.retrieveAllSelectedMenuFunction = retrieveAllSelectedMenuFunction;//已选择功能列表

        vm.gridOptions = {
            multiSelect: true,                                           //多选
            enableRowSelection: true,                                  //允许选中行
            enablePagination:false,
            //showGridFooter:true,
            enableRowHeaderSelection: true,//允许通过点击行首选中行
            enableColumnResizing : true,//设置宽度
            enableGridMenu: true,
            enableFullRowSelection: true ,                              //允许通过点击行任意位置选中行
            modifierKeysToMultiSelect: false,                           //只允许通过键盘辅助多选(前提是允许多选)
            enableSelectAll:true,
            checkOnSelect:true,
            paginationPageSize: 10,
            paginationPageSizes: [10, 20, 50]


        };

        vm.gridOptionsSelected = {
            multiSelect: true,                                           //多选
            enableRowSelection: true,                                  //允许选中行
            enablePagination:false,
            //showGridFooter:true,
            enableRowHeaderSelection: true,//允许通过点击行首选中行
            enableColumnResizing : true,//设置宽度
            enableGridMenu: true,
            enableFullRowSelection: true,                              //允许通过点击行任意位置选中行
            modifierKeysToMultiSelect: false,                           //只允许通过键盘辅助多选(前提是允许多选)
            enableSelectAll:true,
            checkOnSelect:true,
            paginationPageSize: 10,
            paginationPageSizes: [10, 20, 50]

        };

        vm.gridOptions.onRegisterApi = onRegisterApi;

        vm.gridOptionsSelected.onRegisterSelectedApi = onRegisterSelectedApi;

        vm.gridOptions.columnDefs = [
            {field: 'MEENU_NAME', visible: true, name: '模块', pinnedLeft: true,cellTooltip: true,headerTooltip: true},
            {field: 'MENU_FUNCTION', visible: true, name: '功能', pinnedLeft: true,cellTooltip: true,headerTooltip: true}
        ];

        vm.gridOptionsSelected.columnDefs = [
            {field: 'MEENU_NAME', visible: true, name: '模块', pinnedLeft: true,cellTooltip: true,headerTooltip: true},
            {field: 'MENU_FUNCTION', visible: true, name: '功能', pinnedLeft: true,cellTooltip: true,headerTooltip: true}
        ];

        activate();

        return vm;

        function activate() {
            $scope.$on('$viewContentLoaded', function() {
                App.initAjax(); // initialize core components
            });

            // set sidebar closed and body solid layout mode
            $rootScope.settings.layout.pageContentWhite = true;
            $rootScope.settings.layout.pageBodySolid = false;
            $rootScope.settings.layout.pageSidebarClosed = false;
            retrieveAllMenuFunctionm();
            retrieveAllSelectedMenuFunction();
        }

        function onRegisterApi(gridApi) {
            //set gridApi on scope
            vm.gridApi = gridApi;
        }
        function onRegisterSelectedApi(gridApi) {
            //set gridApi on scope
            vm.gridApi = gridApi;
        }

        function retrieveAllMenuFunctionm(){
            var data =[
                {
                    'ID': '123',
                    'MEENU_NAME': '定级管理',
                    'MENU_FUNCTION': '定级信息统计',
                },
                {
                    'ID': '123',
                    'MEENU_NAME': '备案管理',
                    'MENU_FUNCTION': '导入备案信息',
                },{
                    'ID': '123',
                    'MEENU_NAME': '备案管理',
                    'MENU_FUNCTION': '备案单位信息',
                },{
                    'ID': '123',
                    'MEENU_NAME': '备案管理',
                    'MENU_FUNCTION': '备案系统信息',
                },{
                    'ID': '123',
                    'MEENU_NAME': '备案管理',
                    'MENU_FUNCTION': '备案信息统计',
                },{
                    'ID': '123',
                    'MEENU_NAME': '建设整改',
                    'MENU_FUNCTION': '整改信息',
                },{
                    'ID': '123',
                    'MEENU_NAME': '建设整改',
                    'MENU_FUNCTION': '整改情况统计',
                },{
                    'ID': '123',
                    'MEENU_NAME': '等级测评',
                    'MENU_FUNCTION': '测评机构',
                },{
                    'ID': '123',
                    'MEENU_NAME': '等级测评',
                    'MENU_FUNCTION': '测评人员',
                },{
                    'ID': '123',
                    'MEENU_NAME': '等级测评',
                    'MENU_FUNCTION': '测评数据',
                },{
                    'ID': '123',
                    'MEENU_NAME': '等级测评',
                    'MENU_FUNCTION': '测评情况统计',
                }];
            vm.gridOptions.data = data;
        }


        function retrieveAllSelectedMenuFunction(){
            var data =[
                {
                    'ID': '123',
                    'MEENU_NAME': '定级管理',
                    'MENU_FUNCTION': '定级信息查询',
                },
                {
                    'ID': '123',
                    'MEENU_NAME': '备案管理',
                    'MENU_FUNCTION': '备案申请信息',
                },{
                    'ID': '123',
                    'MEENU_NAME': '备案管理',
                    'MENU_FUNCTION': '颁发备案证明',
                },{
                    'ID': '123',
                    'MEENU_NAME': '建设整改',
                    'MENU_FUNCTION': '整改通知',
                },{
                    'ID': '123',
                    'MEENU_NAME': '等级测评',
                    'MENU_FUNCTION': '测评项目',
                },{
                    'ID': '123',
                    'MEENU_NAME': '监督检查',
                    'MENU_FUNCTION': '安全检查',
                }];
            vm.gridOptionsSelected.data = data;
        }
        /**
         * 保存
         */
        function update() {
            swal({
                title: '确认更新保存常用菜单信息?',
                type: 'info',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: '确认',
                cancelButtonText: '取消',
                confirmButtonClass: 'btn btn-success margin-right-10',
                cancelButtonClass: 'btn btn-primary',
                buttonsStyling: false
            }).then(function () {
                swal({
                    title: '提示！',
                    text: '更新成功!',
                    closeOnConfirm: true,
                    type: 'success'
                }).then(function(){
                    cancel();
                });
            });
        }
        /**
         * 关闭弹窗
         */
        function cancel() {
            $uibModalInstance.dismiss('cancel');
        }
    }
})();